/**
 * 开垦
 */
class AddlandPanel extends PanelBase {

	public constructor() {
		super();
		this.skinName = AddlandSkin;
	}


	// 分享按钮
	private btnShare: eui.Button;
	// 好友开垦
	private btnAdd1: eui.Button;
	// 金币开垦
	private btnAdd2: eui.Button;
	// 好友力量
	private labFriendpower: eui.Label;


	protected createChildren() {
		super.createChildren();

		// 设置标题
		this.commonPanel.hideIcon();
		this.commonPanel.setTitle("title_addland_png");

		// 监听
		this.btnAdd1.addEventListener(egret.TouchEvent.TOUCH_TAP, this.addload1, this);
		this.btnAdd2.addEventListener(egret.TouchEvent.TOUCH_TAP, this.addload2, this);
		this.btnShare.addEventListener(egret.TouchEvent.TOUCH_TAP, this.shareTap, this);

		this.labFriendpower.text = String(PlayerSelfData.friend_power);

		// 获取好友力量
		Net.ins.send(['userInfo'], {}, (e) => {
			PlayerSelfData.friend_power = Number(e.power);
			this.labFriendpower.text = String(PlayerSelfData.friend_power);
		});
	}


	/**
	 * 好友开垦
	 */
	private addload1() {
		// 判断好友力量是否够
		if (PlayerSelfData.friend_power < 1) {
			SceneManager.ins.alert("好友力量不足\n邀请好友可得哟")
			return;
		}
		this.doaddload("addLandByChild");
	}


	/**
	 * 金币开垦
	 */
	private addload2() {
		if (PlayerSelfData.gold < 2) {
			SceneManager.ins.alert("金币不足哟")
			return;
		}
		this.doaddload("addLandByGold");
	}


	private doaddload(a: string) {
		Net.ins.send([a], {}, (e) => {
			SceneManager.ins.alert("成功开垦一块新土地");
			PlayerSelfData.addLand(e)
			SceneManager.ins.popScene();
		})
	}


	/**
	 * 点击分享
	 */
	private shareTap() {
		platform.wxshare(2, (e) => { })
	}
}